﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Drawing;

using TreeSharp;

using Styx;
using Styx.Combat.CombatRoutine;
using Styx.Helpers;
using Styx.Logic;
using Styx.Logic.BehaviorTree;
using Styx.Logic.Combat;
using Styx.Logic.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;

namespace FelMaster.Classes.Warlock
{
    class AfflictionDPS : TalentBase
    {
        public override string Name
        {
            get { return "Affliction 1.0"; }
        }

        public override string KeySpell
        {
            get { return "Unstable Affliction"; }
        }

        public override Composite SingleRotation
        {
            get {
                return new PrioritySelector(
                    SC.CastSpell("Life Tap", a => Me.ManaPercent < 35, "Life tap"),
                    SC.CastUniqueSpell("Summon Felhunter", a => (Pet == null || Pet.Dead) && (SC.PlayerHasBuff("Demonic Rebirth") || SC.PlayerHasBuff("Soulburn")), "Summon new Felhunter"),
                    SC.CastSpell("Demon Soul", a => !Me.IsMoving, "Demon Soul while not moving"),
                    SC.CastSpell("Soulburn", a => true, "Soulburn"),
                    SC.CastSpell("Corruption", a => !SC.TargetHasDebuff("Corruption"), "Corruption"),
                    new Decorator(
                        ret => !Me.IsMoving && SC.TargetDebuffTimeLeft("Unstable Affliction") < SC.CastTime("Unstable Affliction"),
                        new PrioritySelector(
                            SC.CastDebuff("Unstable Affliction", a => true, "Unstable affliction")
                        )
                    ),
                    SC.CastSpell("Bane of Doom", a => !SC.TargetHasDebuff("Bane of Doom") && (Me.CurrentTarget.CurrentHealth > 1000000 || Me.CurrentTarget.Name.Contains("Dummy")), "Bane of Doom"),
                    SC.CastSpell("Haunt", a => true, "Haunt"),
                    SC.CastSpell("Summon Doomguard", a => Me.CurrentTarget.CurrentHealth > 5000000, "Doomguard"),
                    SC.ChannelSpell("Drain Soul", a => Me.CurrentTarget.HealthPercent <= 25, "Drain soul"),
                    SC.CastConicSpell("Shadowflame", 11f, 33f, a => true, "ShadowFlame"),
                    SC.CastSpell("Soul Fire", a => SC.PlayerHasBuff("Soulburn"), "Soul Fire"),
                    SC.CastSpell("Shadow Bolt", a => SC.TargetHasDebuff("Corruption") && SC.TargetHasDebuff("Unstable Affliction") && !SC.CanCast("Haunt"), "Shadow Bolt"),
                    SC.CastSpell("Life Tap", a => Me.IsMoving && Me.HealthPercent > Me.ManaPercent && Me.ManaPercent < 80, "Life tap"),
                    SC.CastSpell("Fel Flame", a => Me.IsMoving, "Fel flame")
                );
            }
        }

        public override Composite Buffs
        {
            get
            {
                return new PrioritySelector(
                    SC.CastBuff("Fel Armor", a => true, "Fel Armor"),
                    SC.CastUniqueSpell("Summon Felhunter", a => !Me.Combat && !Me.Mounted && Pet == null || Pet.Dead, "Summon new Felhunter"),
                    SC.CastBuff("Soul Link", a => Pet != null && Pet.IsAlive, "Soul Link")
                );
            }
        }

        public override Composite PVPRotation
        {
            get { throw new NotImplementedException(); }
        }

        public override Composite PVERotation
        {
            get
            {
                return SingleRotation;
            }
        }
    }
}
